from textual.containers import Grid
from textual.screen import ModalScreen
from textual.widgets import Button, Label


class MessageScreen(ModalScreen[bool]):

    def __init__(self, text):
        super().__init__()
        self.text = text

    def key_up(self):
        self.focus_previous()

    def key_left(self):
        self.focus_previous()

    def key_down(self):
        self.focus_next()
        
    def key_right(self):
        self.focus_next()

    def compose(self):
        yield Grid(
            Label(self.text, id="message_text"),
            Button("是", variant="success", id="message_ok"),
            Button("否", variant="error", id="message_cancel"),

            id="message",
        )

    def on_button_pressed(self, event: Button.Pressed) -> None:
        if event.button.id == "message_ok":
            self.dismiss(True)
        else:
            self.dismiss(False)

